<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>fetch get method</title>
</head>
<body>
<script>
    window.onload = () => {
        function getData() {
            fetch('https://httpbin.org/get?name=ckkkkkk').then(data => {
                if (data.ok) {
                    console.log(data)
                    // fetch('https://httpbin.org/post', {
                    //     method: 'POST',
                    //     body: JSON.stringify({name: 'ck', age: 19, cars: ['BMW', "BENZ", "AUDI"]})
                    // })
                    //     .then(res => res.json()) // expecting a json response
                    //     .then(json => {
                    //         try {
                    //             const res = JSON.parse(json.data)
                    //             console.log(res)l
                    //         } catch (e) {
                    //             throw e;
                    //         }
                    //     })
                }
            })
        }

        function postData() {
            fetch('https://httpbin.org/post', {
                method: 'post',
                body: {
                    name: 'ckkkkkk'
                }
            }).then(data => {
                console.log(data.json())
            })
        }

        // getData()
        //     postData()
    }


    async function getDataV2() {
        const data = await fetch('https://httpbin.org/get?name=ckckckckck&age=112121', {
            method: 'get',
            headers: {
                'content-type': ' application/json',
                // 'content-type': 'application/x-www-form-urlencoded'
            }
        })
        console.log(data)
    }

    async function postDataV2() {
        const data = await fetch('https://httpbin.org/post', {
            method: 'post',
            headers: {
                // 'content-type':'application/json'
                // 'content-type':'application/x-www-form-urlencoded'
            },
            body: JSON.stringify({
                name: 'ckkkk',
                age: 20
            })
        })
        console.log(data)
    }

    postDataV2()
    getDataV2()

</script>
</body>
</html>
